/* ----------------------------- Noble Steed Engine----------------------------*
Authors : Daniel Randle, Alex Bourne
Date Created : Mar 13 2013

File:
	nsobjectset.h

Description:
	This file contains the NSObjectSet class which is the base container for all the onjects
	in the game
*---------------------------------------------------------------------------*/

#ifndef NSOBJECTSET_H
#define NSOBJECTSET_H

/* ---------------------------------Class NSObjectSet-----------------------------*

Description:
	NSObjectSet will provide all the needed virtual functions for other deriving classes to use

*-------------------------------------------------------------------------------*/

// includes
#include <global.h>
#include <vector>
#include <nsmath3d.h>
#include <nsobjectreferenceset.h>
#include <nsmaparea.h>
#include <nsobject.h>
#include <map>

class NSObject;
class NSShader;
class NSFrameBufferObject;

class NSObjectSet
{
public:
	typedef std::map<NSShader*,std::vector<NSObject*>>::iterator Iterator;
	typedef std::vector<NSObject*>::iterator ObjectIterator;

	NSObjectSet(NSMapArea * area = NULL);
	~NSObjectSet();

	void addObject(NSShader* shader, NSObject *object);
	NSObject * addObject(NSObject::ObjectType type, NSShader* shader, const std::string & name, const std::string & mfileName="", const std::string & mDirectory="", const std::string & texDir="");

	bool changeObjectShader(const std::string & objectName, NSShader * newShader);
	bool changeObjectShader(NSObject* object, NSShader * newShader);
	bool changeObjectsShader(NSShader * oldShader, NSShader * newShader);

	NSObject * getObject(const std::string & objectName);
	NSObject * getObject(unsigned int objectID);

	bool removeObject(const std::string & objectName);
	bool removeObject(NSObject *object);
	bool removeObjectsShader(NSShader * toRemove);
	bool removeTransObject(NSObject *object);

	void setMapArea(NSMapArea * area);
	void updateRefs(NSObject* baseObj);

	Iterator begin();
	Iterator end();
	Iterator transBegin();
	Iterator transEnd();
	ObjectIterator objectsBegin( NSShader *shader );
	ObjectIterator objectsEnd( NSShader * shader );
private:
	std::map<NSShader*,std::vector<NSObject*>> shaderMap;
	std::map<NSShader*,std::vector<NSObject*>> transObjects;
	std::vector<NSObject*> empty; // This is for returning iterators when the shader
	// object vector for a given shader is not found using objectsBegin/objectsEnd

	NSMapArea * mapArea;
};

#endif